//
//  HomeJDYApi.m
//  SSWiFi
//
//  Created by 酷安 @啥也不会啊啊啊啊啊啊  on 2024/1/24.
//

#import "HomeJDYApi.h"

@interface HomeJDYApi()
@property (copy,nonatomic) NSString *band;
@end


@implementation HomeJDYApi


- (NSString *)devicesName{
    return @"京东云";
}
- (WiFiDeviceTypes)deviceType{
    return WiFiDevice_JDY;
}

- (void)get_Reside_Band{
    NSDictionary *para = @{
        @"cmd":@"GET_RESIDE_BAND",
    };
    MJWeakSelf;
    [self.manage GET:[self serverHost:NO] parameters:para headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSString *v = [responseObject objectForKey:@"result"];
        NSArray  *vs = [v componentsSeparatedByString:@","];
        if(vs.count == 2){
            weakSelf.band = vs.lastObject;
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
}

- (void)setBandPara:(NSString *)bands callBack:(void (^)(bool, NSString * _Nonnull))callback{
    NSDictionary *para = @{
        @"goformId":@"GOFORM_SET_BAND",
        @"band_list":bands,
    };
    [self.manage GET:[self serverHost:YES] parameters:para headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if([[responseObject objectForKey:@"result"] isEqualToString:@"success"]){
            !callback ? : callback(YES,@"更改成功,设备重启中..");
            return;
        }
        !callback ? : callback(NO  ,@"更改失败");
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        !callback ? : callback(NO  ,@"更改失败");
    }];
}

- (void)getSupportBandCallBack:(void (^)(NSArray<BandItemModel *> * _Nullable))callback{
    NSDictionary *para = @{
        @"cmd":@"get_support_band",
    };
    [self.manage GET:[self serverHost:NO] parameters:para headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSMutableArray *arr = [NSMutableArray array];
        for (NSString *key in responseObject) {
            if([responseObject[key] integerValue] == 1){
                [arr addObject:key];
            }
        }
        NSArray *array2 = [arr sortedArrayUsingSelector:@selector(compare:)];
        NSMutableArray *rsp = [NSMutableArray array];
        for(NSString *itm in array2){
            [rsp addObject:[[BandItemModel alloc] initWithName:itm value:0]];
        }
        !callback ? : callback(rsp);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        !callback ? : callback(nil);
    }];
}

- (void)getSelectedBandCallBack:(void (^)(NSString * _Nullable bands))callback{
    NSDictionary *para = @{
        @"cmd":@"set_band_list",
    };
    [self.manage GET:[self serverHost:NO] parameters:para headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSString *v = [responseObject objectForKey:@"set_band_list"];
        !callback ? : callback(v);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        !callback ? : callback(nil);
    }];
}

- (NSDictionary *)setIMEIPara:(NSString *)newImei{
    NSDictionary *para = @{
        @"goformId": @"SET_IMEI_NUM",
        @"imei": newImei,
    };
    return para;
}
@end
